<?php

if(!defined("INDEX"))
    die;

if(!check_request('type'))
    throw new HackException();

// ----------------------------------------------------------------------------

$type = trim($_REQUEST['type']);

$smarty->assign('type', $type);

$release_list = new ReleaseList();

switch($type) {

    case 'recently_added':

        if(isset($_REQUEST['filter_recent_schedules'])) {

            try {
                $tag = new Tag;
                $tag->name = $_REQUEST['filter_recent_schedules'];

                $smarty->assign('recent_schedules', $release_list->getRecentAddedSchedulesByTag($tag->name, 0, $user->id));

            } catch(Exception $e) {

                $smarty->assign('recent_schedules', $release_list->getRecentAddedSchedules(0, $user->id));
            }

        } else {

            $smarty->assign('recent_schedules', $release_list->getRecentAddedSchedules(0, $user->id));
        }

        break;

    case 'just_released':

        if(isset($_REQUEST['filter_recent_releases'])) {

            try {
                $tag = new Tag;
                $tag->name = $_REQUEST['filter_recent_releases'];

                $smarty->assign('recent_releases', $release_list->getRecentReleasesByTag($tag->name, 0));

            } catch(Exception $e) {

                $smarty->assign('recent_releases', $release_list->getRecentReleases(0));
            }

        } else {

            $smarty->assign('recent_releases', $release_list->getRecentReleases(0));
        }

        break;

    case 'upcoming_releases':

        if(isset($_REQUEST['filter_upcoming'])) {

            try {
                $tag = new Tag;
                $tag->name = $_REQUEST['filter_upcoming'];

                $smarty->assign('upcoming_schedules', $release_list->getUpcomingSchedulesByTag($tag->name, 0, $user->id));

            } catch(Exception $e) {

                $smarty->assign('upcoming_schedules', $release_list->getUpcomingSchedules(0, $user->id));
            }

        } else {

            $smarty->assign('upcoming_schedules', $release_list->getUpcomingSchedules(0, $user->id));
        }


        /* ANNOUNCED SCHEDULES */

        if(isset($_REQUEST['filter_upcoming'])) {

            try {
                $tag = new Tag;
                $tag->name = $_REQUEST['filter_upcoming'];

                $smarty->assign('announced_schedules', $release_list->getAnnouncedSchedulesByTag($tag->name, 0, $user->id));

            } catch(Exception $e) {

                $smarty->assign('announced_schedules', $release_list->getAnnouncedSchedules(0, $user->id));
            }

        } else {

            $smarty->assign('announced_schedules', $release_list->getAnnouncedSchedules(0, $user->id));
        }

        break;

    default:
        header('Location: /');
        
        exit;

}